package com.itwn.comic.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.itwn.comic.entity.Permission;
import com.itwn.comic.mapper.PermissionMapper;
import com.itwn.comic.vo.PermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionService {
    @Autowired
    PermissionMapper permissionMapper;
    //加载主菜单
    public List<PermissionVo> initLoadAllPermission(){
        return permissionMapper.initLoadAllPermission();
    }
    //条件查询
   public PageInfo<PermissionVo> listByPage(Integer now,Integer size,String name){
       PageHelper.startPage(now,size);
       List<PermissionVo> list = this.permissionMapper.selectPermissionByName(name);
       return new PageInfo<>(list);
   }
    //加载父菜单
    public List<PermissionVo> initAllByParentMenu(){
        return permissionMapper.selectAllByParentMenu();
    }
    
    public void modify(Permission permission){
        this.permissionMapper.updateByPrimaryKey(permission);
    }
    //添加权限
    public void add(Permission permission){
        this.permissionMapper.insert(permission);
    }

    public void remove(long id){
        this.permissionMapper.deleteByPrimaryKey(id);
    }

    public List<Integer> queryMenuByRole(int id){
        return this.permissionMapper.selectMenuByRole(id);
    }

    public List<PermissionVo> initLoadAllPermissionByPermissionId(long id) {
        return permissionMapper.selectPermissionByUserId(id);
    }
}
